﻿using ComLib.ComFun;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;

namespace YSLPages
{
    public class SignatureFun
    {
        public static bool MakeSignatureZipFile(string bmpFileSrc,string zipFile,out string _strMessage)
        {
            _strMessage = "";
            try
            {

                if (File.Exists(bmpFileSrc))
                {
                    //byte[] data = new ComLib.ComFun.BufferManage().GetJPEGByteArray(bmpFileSrc);
                    //using (MemoryStream ms = new MemoryStream(data))
                    //{
                        //string strBmpFileName = Path.Combine(saveDir, ywbh + ".bmp");
                        //string strZipFileName = Path.Combine(saveDir, ywbh + ".zip");

                        //if (File.Exists(strBmpFileName))
                        //    File.Delete(strBmpFileName);

                        if (File.Exists(zipFile))
                            File.Delete(zipFile);

                        //Bitmap gif = new Bitmap(ms);

                        //_imgSignature = gif;
                        //_strImgFile = strBmpFileName;

                        //gif.Save(strBmpFileName, ImageFormat.Bmp);    //转成bmp                  

                        byte[] scr = IPCCom.ReadByteArray(bmpFileSrc);

                        int outZipLength = 0;
                        int outBufLength = scr.Length + 10;

                        byte[] outBuffer = new byte[outBufLength];

                        int nRes = SegSignature.SegmentSignature_Mem(scr, scr.Length, outBuffer, outBufLength, ref outZipLength);
                        if (1 == nRes)
                        {
                            IPCCom.ByteToDat(outBuffer, outZipLength, zipFile);
                            //zipFile = strZipFileName;
                            return true;
                        }
                        else
                        {
                            _strMessage = "生成签名失败！代码:" + nRes.ToString();
                        }
                    //}
                }
                else
                {
                    _strMessage = "签名为空";
                }
            }
            catch (Exception ex)
            {
                _strMessage = ex.ToString();
            }

            return false;
        }
    }
}
